from abc import ABCMeta, abstractmethod


class Observer(metaclass=ABCMeta):
    @abstractmethod
    def update(self, notice):
        pass


class Notice:
    def __init__(self):
        self.observers = []

    def attach(self, obs):
        self.observers.append(obs)

    def detach(self, obs):
        self.observers.remove(obs)

    def notify(self):
        for obs in self.observers:
            obs.update(self)


class StaffNotice(Notice):

    def __init__(self, company_info):
        super().__init__()
        self.__company_info = company_info

    @property
    def company_info(self):
        return self.__company_info

    @company_info.setter
    def company_info(self, info):
        self.__company_info = info
        self.notify()


class Staff(Observer):
    def __init__(self):
        self.company_info = None

    def update(self, notice):
        self.company_info = notice.company_info


notice_obj = StaffNotice("init company")
s1 = Staff()
s2 = Staff()
notice_obj.attach(s1)
notice_obj.attach(s2)


notice_obj.company_info = "发点奖金"
print(s1.company_info)
print(s2.company_info)
notice_obj.detach(s1)
notice_obj.detach(s2)
notice_obj.company_info = "放假了 "
print(s1.company_info)
print(s2.company_info)
